package com.springboot.controller.base;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.springboot.constant.ErrorCodeConstants;
import com.springboot.pojo.ResponsePojo;

@RestController
public class CustomErrorController implements ErrorController {
	private static final String ERROR_PATH = "/error";

	@RequestMapping(value = ERROR_PATH)
	public ResponsePojo<JSONObject> handleError(HttpServletRequest request) {
		ResponsePojo<JSONObject> resPojo = new ResponsePojo<JSONObject>();
		resPojo.setCode(ErrorCodeConstants.ERROR_404);
		resPojo.setDesc("Error Controller");
		resPojo.setBody(null);
		return resPojo;
	}

	@Override
	public String getErrorPath() {
		return ERROR_PATH;
	}

}
